﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EPiServer.Web.Hosting;
using Microsoft.WindowsAzure.StorageClient;

namespace DBLOG.Azure.VirtualPathProvider.Entities
{
    class CloudSummary : UnifiedSummary
    {
        private CloudBlob _Blob { get; set; }

        public CloudSummary(CloudBlob blob)
        {
            this._Blob = blob;
        }

        public override void SaveChanges()
        {
            // TODO: The blob is NULL when at the virtual path root
            if (this._Blob != null)
            {
                this._Blob.SetMetadata();
            }
        }

        public override string Author
        {
            get
            {
                return _Blob.Metadata["Author"] as string;
            }
            set
            {
                if (!String.IsNullOrEmpty(value))
                {
                    _Blob.Metadata["Author"] = value;
                }
            }
        }

        public override string Keywords
        {
            get
            {
                return _Blob.Metadata["Keywords"] as string;
            }
            set
            {
                if (!String.IsNullOrEmpty(value))
                {
                    _Blob.Metadata["Keywords"] = value;
                }
            }
        }

        public override string Title
        {
            get
            {
                return _Blob.Metadata["Title"] as string;
            }
            set
            {
                if (!String.IsNullOrEmpty(value))
                {
                    _Blob.Metadata["Title"] = value;
                }
            }
        }

        public override string Category
        {
            get
            {
                return _Blob.Metadata["Category"] as string;
            }
            set
            {
                if (!String.IsNullOrEmpty(value))
                { 
                    _Blob.Metadata["Category"] = value;
                }
                
            }
        }

        public override string Subject
        {
            get
            {
                return _Blob.Metadata["Subject"] as string;
            }
            set
            {
                if (!String.IsNullOrEmpty(value))
                {
                    _Blob.Metadata["Subject"] = value;
                }
            }
        }

        public override string Comments
        {
            get
            {
                return _Blob.Metadata["Comments"] as string;
            }
            set
            {
                if (!String.IsNullOrEmpty(value))
                {
                    _Blob.Metadata["Comments"] = value;
                }
            }
        }

        public override bool CanPersist
        {
            get { return true; }
        }
    }
}
